! phas to deg or dge to phas
module feather
    implicit none 

    type thap
        real :: c, a, p 
    end type thap 

    type thcs
        real :: c, lc, ls
    end type thcs 

end module feather


program p2d
    use feather
    implicit none
    
    integer :: typenum
    type(thap) :: ap 
    type(thcs) :: cs 

    write(*,"(A35)") "The input Type of data is:"
    write(*,"(A35)") "=== 1. Ampl and Phas"
    write(*,"(A35)") "=== 2. Th1c and Th1s"
    write(*,"(A35)") "Please input 1 or 2 :"
    read(*,"(I1)") typenum 

    if(typenum==1) then 
        write(*,"(A35)") "Please input Ampl:"
        read(*,*) ap%a 
        write(*,"(A35)") "Please input Phas:"
        read(*,*) ap%p 

        cs%lc = -ap%a*cos(ap%p) 
        cs%ls = -ap%a*sin(ap%p) 
        
        write(*,"(A35,F6.3)") "=== Th1c is: ", cs%lc 
        write(*,"(A35,F6.3)") "=== Th1s is: ", cs%ls 

    elseif(typenum==2) then 
        write(*,"(A35)") "Please input Th1c:"
        read(*,*) cs%lc 
        write(*,"(A35)") "Please input Th1s:"
        read(*,*) cs%ls 

        ap%a = sign(1.0,-cs%lc)*sqrt(cs%lc**2+cs%ls**2)
        ap%p = atan(cs%ls/cs%lc)

        write(*,"(A35,F6.3)") "=== Ampl is: ", ap%a  
        write(*,"(A35,F6.3)") "=== Phas is: ", ap%p  

    else 
        write(*,"(A35)") "Error: Invaild Input!"
    end if 
        
end program p2d
